package com.ys.web.app.controller;

import com.ys.utils.base.http.ResponseHandler;
import com.ys.utils.base.j2se.MapHandler;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.spring.properties.Config;
import com.ys.web.app.model.BaseTerminalPO;
import com.ys.web.app.service.TerminalService;
import com.ys.web.app.vo.AuditVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ 名称:
 * @ 创建人: dhf
 * @ 参数： null
 * @ 创建时间: 2022/5/10
 * @ 修改人和其它信息
 * @ 返回值:
 */
@Slf4j
@RestController
@RequestMapping("/terminal")
public class TerminalController {


    @Autowired
    private TerminalService terminalService;


    /**
     * 当前app 是否实在审核期间
     *
     * @param useVersion
     * @return
     */
    @RequestMapping("/isAudit")
    public String isAudit(String useVersion, String terminal) {
        AuditVO auditVO = new AuditVO();
        auditVO.setIsAudit(true);
        BaseTerminalPO currentObject = terminalService.getCurrentVersion(terminal == null ? "ios" : "android");
        if(StringHandler.isNotEmpty(currentObject)) {
            if ("android".equalsIgnoreCase(terminal)) {
                auditVO.setIsAudit(StringHandler.getInt(useVersion) > currentObject.getVersion());
            } else {
                Double currentVersion = StringHandler.getDouble(currentObject.getAppVersion());
                Double userVersion = StringHandler.getDouble(useVersion);
                auditVO.setIsAudit(userVersion>currentVersion);
            }
        }
        return ResponseHandler.success(auditVO);
    }

    @RequestMapping("/getCurrentVersion")
    public String getCurrentVersion(String terminal) {
        return ResponseHandler.success(terminalService.getCurrentVersion(terminal == null ? "ios" : "android"));
    }

    @RequestMapping("/aboutUs")
    public String aboutUs() {
        return ResponseHandler.success(MapHandler.initMap(
                "website", Config.pp.get("about.us.website"),
                "email", Config.pp.get("about.us.email"),
                "phone", Config.pp.get("about.us.phone"),
                "complan", Config.pp.get("about.us.complan")));
    }

}
